<!-- AutoNantExternal.xslt - Generate a Nant build file for external assemblies 
   - Tamara Roberson <tamara.roberson@gmail.com>
   - v.0.0.2 (2007-02-11)
   - RELEASED IN THE PUBLIC DOMAIN
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
	<xsl:output method="xml" indent="yes" />
	<xsl:variable name="debug">true</xsl:variable>

	<!-- MAIN -->
	<!-- Ensure that we only generate a file if we have
	     externals to build -->
	<xsl:template match="/">
		<xsl:if test="/autonant/externals">
			<xsl:apply-templates />
		</xsl:if>
	</xsl:template>

	<!-- AutoNant -->
	<xsl:template match="autonant">
		<project name="{@name}-externals" default="build" basedir="..">
			<!-- Description -->
			<xsl:apply-templates select="description" />

			<!-- Properties -->
			<property
			  name="debug"
			  overwrite="false"
			  value="{$debug}" />
			<property
			  name="base.dir"
			  overwrite="false"
			  value="${{project::get-base-directory()}}" />
	  		<property
			  name="bin.dir"
			  value="${{base.dir}}/bin" />
	  		<property
			  name="external.dir"
			  value="${{base.dir}}/external" />
	  		<property
			  name="src.dir"
			  value="${{base.dir}}/src" />
			<property
			  name="filename"
			  overwrite="false"
			  value="default.autonant" />
			<property
			  name="buildfile"
			  value="${{filename}}.build" />
			<property
			  name="buildfile_path"
			  value="${{path::combine (build.dir, buildfile)}}" />
			<property
			  name="external_buildfile"
			  value="${{filename}}-external.build" /> 
			<property
			  name="external_buildfile_path"
			  value="${{path::combine (build.dir, external_buildfile)}}" />

			<!-- Targets -->
			<xsl:call-template name="target-build" />
			<xsl:call-template name="target-clean" />
		</project>
	</xsl:template>

	<!-- Description -->
	<xsl:template match="description">
		<description>
			<xsl:value-of select="." />
			<xsl:text> (external assemblies)</xsl:text> 
		</description>
	</xsl:template>	

	<!-- Target-Build -->
	<xsl:template name="target-build">
		<target name="build" description="compiles the source code">
			<mkdir dir="${{bin.dir}}" failonerror="false" />

			<nant target="build" inheritall="false">
				<xsl:call-template name="all-module-builds" />
			</nant>

			<xsl:for-each select="externals/module">
				<copy todir="${{bin.dir}}">
					<fileset basedir="${{external.dir}}/{.}/bin/">
						<include name="*" />
					</fileset>
				</copy> 
			</xsl:for-each>
		</target>
	</xsl:template>

	<!-- Target-Clean -->
	<xsl:template name="target-clean">
		<target name="clean" description="remove all generated files">
			<nant target="clean" inheritall="false">
				<xsl:call-template name="all-module-builds" />
			</nant>

			<delete failonerror="false">
				<fileset basedir="${{external.dir}}" defaultexcludes="false">
					<include name="**/*~" />
				</fileset>
			</delete>
		</target>
	</xsl:template>

	<!-- All-Module-Builds -->
	<xsl:template name="all-module-builds">
		<buildfiles>
			<xsl:for-each select="externals/module">
				<include name="${{external.dir}}/{.}/default.build" />
			</xsl:for-each>
		</buildfiles>
	</xsl:template>
</xsl:stylesheet>

